$(function(){
	
	// photo-picker
	$('.upload-wrap').each(function(){
	    var file = $(this).children('input[type=file]');
	    
	    file.change(function(){
	            var c = $(this).parent();
	            c
	                    .addClass('selected')
	                    .attr('title', this.value);
	            /*c.children('.add')
	                    .attr('onclick', '');*/
	                    
	            //wrap.children('input[type=file]').val('');
	    });
	});
	
	// photo-list
	$('.photo-list').sortable({
	    revert: 'invalid',
	    items:  'li:not(.control)',
	    cursor: 'move',
	    stop: function(e, ui) {
	            $(this).children('li:not(.control)').each(function(index) {
	                    $(this).find('input[type=hidden].position').val(index)
	            });
	    }
	});
	
	// CKEDITOR
	$('.ckedit').each(function(){
		var txt = $(this);
		
		var toolbarGroup = 'Basic';
		if (txt.hasClass('full')) {
			toolbarGroup = 'Full';
		}
		
		CKEDITOR.replace(this, {
			language: 'sr',
			toolbarGroups: CKEDITOR_toolbars[toolbarGroup],
			contentsCss: '/css/style.css',
			bodyId:      'content'
		});
		CKFinder.setupCKEditor( null, '/js/ckfinder/' );
	});
	
});
